﻿using System;

namespace ODM.Data.Model
{
    public class DataValue
    {
        #region Old Code
        //public DataValue()
        //{

        //}

        //public DataValue(DataValue source)
        //{
        //    this.ID = source.ID;
        //    this.Value = source.Value;
        //    this.DateTime = source.DateTime;
        //    this.CensorCode = source.CensorCode;
        //    this.QualifierID = source.QualifierID;
        //    this.OffsetTypeID = source.OffsetTypeID;
        //    this.SiteID = source.SiteID;
        //    this.SourceID = source.SourceID;
        //    this.VariableID = source.VariableID;
        //    this.MethodID = source.MethodID;
        //    this.QualityControlLevelID = source.QualityControlLevelID;
        //    this.ValueAccuracy = source.ValueAccuracy;
        //    this.DerivedFromValueID = source.DerivedFromValueID;
        //    this.OffsetValue = source.OffsetValue;
        //    this.SampleID = source.SampleID;
        //    this.UTCOffset = source.UTCOffset;
        //    this.UTCDateTime = source.UTCDateTime;
        //}

        //public int ID { get; set; }

        //public double Value { get; set; }

        //public DateTime DateTime { get; set; }

        //public string CensorCode { get; set; }

        //public int? QualifierID { get; set; }

        //public int? OffsetTypeID { get; set; }

        //public int SiteID { get; set; }

        //public int SourceID { get; set; }

        //public int VariableID { get; set; }

        //public int MethodID { get; set; }

        //public int QualityControlLevelID { get; set; }

        //public double? ValueAccuracy { get; set; }

        //public int? DerivedFromValueID { get; set; }

        //public double? OffsetValue { get; set; }

        //public int? SampleID { get; set; }

        //public double UTCOffset { get; set; }

        //public DateTime UTCDateTime { get; set; }

        #endregion

        public DataValue()
        {

        }

        public DataValue(DataValue source)
        {
            this.ID = source.ID;
            this.Value = source.Value;
            this.DateTime = source.DateTime;
            this.CensorCode = source.CensorCode;
            if (source.Qualifier != null)
                this.Qualifier = new Qualifier(source.Qualifier);
            if (source.OffsetType != null)
                this.OffsetType = new OffsetType(source.OffsetType);
            if (source.Site != null)
                this.Site = new Site(source.Site);
            if (source.Source != null)
                this.Source = new Source(source.Source);
            if (source.Variable != null)
                this.Variable = new Variable(source.Variable);
            if (source.Method != null)
                this.Method = new Method(source.Method);
            if (source.QualityControlLevel != null)
                this.QualityControlLevel = new QualityControlLevel(source.QualityControlLevel);
            this.ValueAccuracy = source.ValueAccuracy;
            this.DerivedFromValueID = source.DerivedFromValueID;
            if (source.OffsetType != null)
                this.OffsetType = new OffsetType(source.OffsetType);
            if (source.Sample != null)
                this.Sample = new Sample(source.Sample);
            this.UTCOffset = source.UTCOffset;
        }
        
        public int ID { get; set; }

        public double Value { get; set; }

        public DateTime DateTime { get; set; }

        public string CensorCode { get; set; }

        public Qualifier Qualifier { get; set; }

        public Site Site { get; set; }

        public Source Source { get; set; }

        public Variable Variable { get; set; }

        public Method Method { get; set; }

        public QualityControlLevel QualityControlLevel { get; set; }

        public double? ValueAccuracy { get; set; }

        public int? DerivedFromValueID { get; set; }

        public OffsetType OffsetType { get; set; }

        public double? OffsetValue { get; set; }

        public Sample Sample { get; set; }

        public double UTCOffset { get; set; }

        public DateTime UTCDateTime
        {
            get
            {
                return this.DateTime.AddHours(-this.UTCOffset);
            }
        }

    }
}
